var work={
	/*·····························初始化························*/
	init:function(){
		this.eventListen();
		this.dataTable();
	},
	/*·····························事件监听························*/
	eventListen:function(){
		// 按钮颜色切换和取值放入隐藏域
		$(document).on("click","#buttonGroup button",function(){
			$("#Bcate").attr("value",$(this).text());
			$("#buttonGroup button").removeClass("btn-primary");
			$(this).addClass("btn-primary");
			var signId="#Scate";
			var type=$(this).attr("type");
			work.getDict(signId,type);
		});
// 搜索按钮点击
		$(document).on("click","#searchBtn",function(){
			info.keyword=$("#searchName").val();
			$("#orderTable").dataTable().api().draw();
		});
//回车搜索界面
// // 回车事件
	    document.onkeydown = function(e){
	                 var ev = document.all ? window.event : e;
	                 if(ev.keyCode==13) {
	                   e.preventDefault();
	                    info.keyword=$("#searchName").val();
	                   $("#orderTable").dataTable().api().draw();
	                 }
	    }
	// 查看详情按钮
		$(document).on("click",".infoBtn",function(){
			var id=$(this).attr("uid");
			var url='/index.php?m=Service&c=Order&a=info&ID='+id;
			work.layerOpen('工单详情',url,'800px','500px');
		});
	},
	/*·····························功能性函数························*/
	// iframe页面弹窗
	layerOpen:function(title,url,w,h){
		(w==null)?w='800px':w=w;
		(h==null)?h='600px':h=h;
		layer.open({
			type: 2,
			area: [w,h],
			fix: false, //不固定
			maxmin: true,
			shade:0.4,
			title: title,
			content:url,
		});
	},
	
	/*·····························插件初始化························*/
	dataTable:function(){
		  var table=$("#orderTable");
	      var t=table.dataTable({
	        "ajax":function(data,callback,setting){
	          var page = table.api().page.info();
	          $.post("/index.php?m=Service&c=Order&a=search",{pageIndex:page.page+1,pageSize:page.length,select:info.keyword,customer_id:info.customerId},function(data,status){
	            console.log(data);
	              callback(data); 
	          });
	        },

	        "pageLength":10,
	          "ordering":false,
	          "deferRender": true,
	          "columns":[
	          {"data":"ID"},
	          {"data":"TO_DEPT"},
	          {"data":"DATA_9"},
	          {"data":"DATA_10"},
	          {"data":"DATA_12"},
	          {"data":"DATA_11"},
	          {"data":"work_level"},
	          {"data":"create_time"},
	          {"data":"ID"},
	          ],
	          "columnDefs":[
	           {
	            "targets":1,
	            "data":"TO_DEPT",
	            "render":function(data,type,full,meta){
	            	if(data==null){
	            		var poStr='未指派';
	            	}else{
	            		var poStr='已指派';
	            	}
	              
	              return poStr;
	            }

	          },
	           {
	            "targets":6,
	            "data":"work_level",
	            "render":function(data,type,full,meta){
	              	switch(data){
	              		case '0':
	              			return '普通';
	              			break;
	              		case '2':
	              			return '<span class="c-red">紧急</span>';
	              			break;
	              	}
	            }

	          },
	          {
	            "targets":8,
	            "data":"id",
	            "render":function(data,type,full,meta){
	              var poStr='<a href="javascript:;" uid="'+data+'" class="label label-success radius infoBtn">查看详情</a>';
	              return poStr;
	            }

	          },
	          ],
	        "fnCreatedRow":function(row,data,index){
	          //row 表示当前tr，data表示当前行的元素对象，index表示当前tr索引
	        },
	      "bPaginate": true, //翻页功能
	      // "processing": true,
	      "searching":false,
	      "serverSide": true,//服务器模式
	        });
		},
}